package day16MysSQL;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

import java.security.MessageDigest;

public class Demo05Register {
    private static final String baseUrl = "jdbc:mysql://localhost:3306/2307e_04?useSSL=false&serverTimeZone=Asia/Shanghai\", \"root\", \"root";
    private static final String username = "root";
    private static final String password = "root";

    public static void main(String[] args) throws SQLException {

        Scanner sc = new Scanner(System.in);

        System.out.println("请输入姓名");
        String nickName = checkValue(1, sc);

        System.out.println("请输入账号");
        String username = checkValue(2, sc);

        System.out.println("请输入密码");
        String password = checkValue(3, sc);

        // TODO 检查账号是否重复
        JDBCUtil util = new JDBCUtil();
        String checkSql = "";
        ResultSet checkRes = util.executeQuery(checkSql);
        if (checkRes.next()) {
            // 说明重了 todo
        }
        String sql = String.format("insert into sys_user (`nick_name`, `username`, `password`) values ('%s', '%s', '%s')", nickName, username, password);

        // --
        // 查询 select * from sys_user where username = 'admin' and password = '1213454'
        int row = util.executeUpdate(sql);
        System.out.println(row);
    }

    public static String checkValue(int type, Scanner sc) {

        String val = sc.next();
        while (val.trim().length() == 0) {
            System.out.println(type == 1 ? "请重新输入姓名" : (type == 2 ? "请重新输入账号" : "请重新输入密码"));
            val = sc.next();
        }
        return val;
    }
    // 1.checkValue()
    // 2.封装 JDBCUtils
    // 3.注册中使用 封装
    // 4.登录中使用 封装
    // 5.加密包的使用
    // 6.账号查重
}
